package com.example.consumer.config;

import com.example.demo.service.DemoService;
import org.apache.dubbo.config.spring.ReferenceBean;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description:
 * @Author: yangzhiwei
 * @Date: 2021/9/14 11:29
 */
@Configuration
@EnableDubbo
public class DubboConfig {
    @Bean
    ReferenceBean<DemoService> referenceBean() {
        // 注册一个ReferenceBean<GreetingService>类型的普通bean
        ReferenceBean<DemoService> referenceBean = new ReferenceBean<>();
        referenceBean.setId("greetingService");
        referenceBean.setInterface(DemoService.class);
        referenceBean.setVersion("1.0.0");
        return referenceBean;
    }

    @Bean
    DemoService greetingService() {
        // 注册一个GreetingService类型的普通bean
        return (DemoService) referenceBean().getObject();
    }
}